package gui.cen.table;

import core.utils.EPara;
import core.utils.Utils;
import gui.cen.Center;
import gui.processor.Processor;
import gui.processor.Worker;
import gui.utils.Para;
import gui.utils.SliderWrap;
import gui.utils.Slider;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.JButton;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class TableOpts extends JPanel implements ActionListener{
    private JButton st, sa;
    public static int HEIGHT_OF_OPTIONS = 176;
    private Center center;
    public TableOpts(Center center){
        super(new BorderLayout());
        this.center = center;
        this.setPreferredSize(new Dimension(Center.WIDGE_WIDTH, HEIGHT_OF_OPTIONS));
        setBackground(new Color(102, 102, 102));
        setBorder(BorderFactory.createLineBorder(new Color(178, 178, 178), 2));

        JPanel p = new JPanel();
        p.setOpaque(false);
        p.setBorder(BorderFactory.createEmptyBorder(0,5,0,5));
        p.setLayout(new GridLayout(5,1));
        p.add(new SliderWrap(Slider.FRAME, 3, 1, Para.FRAME, "Frame", 75, 3, center, false, 0, new Color(178, 178, 178), new DecimalFormat("#0.00")));
        p.add(new SliderWrap(Slider.MIN_FREQ_HIGHLIGHT, 100, 0, EPara.MIN_FREQ_HIGHLIGHT, "Min. Freq.", 75, 3, center, true, 100, new Color(178, 178, 178), new DecimalFormat("#0.00")));
        p.add(new SliderWrap(Slider.HPS_HIGHLIGHT, 10, 0, EPara.HPS_LENGTH, "Max. HPS", 75, 3, center, false, 0, new Color(178, 178, 178), new DecimalFormat("#0.00")));
        p.add(Utils.getButton(st = new JButton("Save Selected Rows"), 180, 25, new Color(102, 102, 102), new Color(178, 178, 178), this, "Save Selected Rows"));
        p.add(Utils.getButton(sa = new JButton("Save Additional Data"), 180, 25, new Color(102, 102, 102), new Color(178, 178, 178), this, "Entropy, non-consensus count, indels"));
        this.add(p, BorderLayout.CENTER);
    }

    public void actionPerformed(ActionEvent evt){
        Object source = evt.getSource();
        if(source==st){
            Processor processor = new Processor(center);
            processor.setTask(Para.TASK_TSAVE);
            Worker sl = new Worker(processor);
            sl.execute();
        }
        else if(source==sa){
            Processor processor = new Processor(center);
            processor.setTask(Para.TASK_SAVE_INDELS);
            Worker sl = new Worker(processor);
            sl.execute();
        }
    }  
}